import math

def my_abs(x):
    if not isinstance(x,(int,float)):
        raise TypeError("参数类型错误，应为int或者float")
    if x>=0:
        return x
    else:
        return -x

# 求解一元二次方程
def quadratic(a,b,c):
    f=b*b-4*a*c
    if f<0:
        return '无解' # 返回类型是str
    ff=math.sqrt(f)
    x1=(-b+ff)/(2*a)
    x2=(-b-ff)/(2*a)
    if x1==x2:
        return x1 # 返回类型是float
    return x1,x2 # 返回类型是tuple

def my_add(x,n=1) :
    return x+n

def sum(*num): 
    sum = 0
    for i in num :
        sum += i
    return sum

def person( name , age , **kw ):  # 关键字参数，可变参数，关键字参数必须在可变参数后面
    print("-----------------")
    print('name:',name)
    print("age:",age)
    if 'city' in kw:
        print("city:",kw['city'])
    if 'job' in kw:
        print("job:",kw['job'])
    print("-----------------")
    
def move(n,a,b,c):
    if n==1:  # 递归出口，当n=1时，直接将盘子从a移动到c
        print(a,'-->',c)
    else:
        move(n-1,a,c,b) # 将A的n-1个盘子移到B，借助c
        move(1,a,b,c) # 将A的最后一个盘子移到C
        move(n-1,b,a,c) # 将B的n-1个盘子移到C，借助a
        
def my_trim(s):  # 去除字符串首尾的空格
    flag1=0
    flag2=0
    for i in range(len(s)):
        if flag1==0 and s[i]!=' ':  # 找到第一个不是空格的字符的位置
            flag1=i
        if s[i]!=' ':
            flag2=i
    return s[flag1:flag2+1]

def my_fib(max):
    a,b=0,1
    for n in range(max):
        yield b
        a,b=b,a+b # 细节，等价于 t=(b,a+b) a=t[0] b=t[1]
    return 'END'

def yanhui_triangles():
    res0=[1]
    while True:
        yield res0
        res1=[1]
        for i in range(len(res0)-1):
            res1.append(res0[i]+res0[i+1])
        res1.append(1)
        res0=res1